package com.data.monitoring.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import org.springframework.stereotype.Component;

@Component
public class EncryptionUtil {
    
    // 从配置文件中读取，实际项目应该放在安全配置中
    @Value("${encryption.password}")
    private String encryptionPassword;
    
    @Value("${encryption.salt}")
    private String encryptionSalt;
    
    public String encrypt(String data) {
        TextEncryptor encryptor = Encryptors.text(encryptionPassword, encryptionSalt);
        return encryptor.encrypt(data);
    }
    
    public String decrypt(String encryptedData) {
        TextEncryptor encryptor = Encryptors.text(encryptionPassword, encryptionSalt);
        return encryptor.decrypt(encryptedData);
    }
}